package com.yk.anima.controller;

import com.yk.anima.api.ProductsDogApi;
import com.yk.anima.pojo.ProductsDog;
import com.yk.anima.response.QueryResponseResult;
import com.yk.anima.response.ResponseResult;
import com.yk.anima.servlet.ProductsDogServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaokai
 * @create 2021-05-13 22:32:36
 * @desc...对狗进行管理
 */
@RestController
@RequestMapping("/dog")
public class ProductsDogController implements ProductsDogApi {

    @Autowired
    ProductsDogServlet productsDogServlet;

    /**
     * @Author xiaoKai
     * @Description 查询所有狗类
     * @Date 20:24 2021/5/14
     * @param
     * @return java.util.List<com.yk.anima.pojo.ProductsDog>
     */
    @Override
    @GetMapping("/findAll")
    public List<ProductsDog> findAll() {
        return productsDogServlet.findAll();
    }

    /**
     * @Author xiaoKai
     * @Description 根据ID查询狗
     * @Date 20:27 2021/5/14
     * @param id
     * @return com.yk.anima.pojo.ProductsDog
     */
    @Override
    @GetMapping("/findById/{id}")
    public ProductsDog findById(@PathVariable("id") int id) {
        return productsDogServlet.findById(id);
    }

    /**
     * @Author xiaoKai
     * @Description 添加狗
     * @Date 20:29 2021/5/14 
     * @param productsDog 
     * @return com.yk.anima.response.ResponseResult
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ProductsDog productsDog) {
        productsDog.setDogId(3);
        productsDog.setpId(null);
        return productsDogServlet.save(productsDog);
    }

    /**
     * @Author xiaoKai
     * @Description 根据ID删除狗
     * @Date 20:32 2021/5/14 
     * @param id 
     * @return com.yk.anima.response.ResponseResult
     */
    @Override
    @DeleteMapping("/deleteById/{id}")
    public ResponseResult deleteById(@PathVariable("id") int id) {
        return productsDogServlet.deleteById(id);
    }

    /**
     * @Author xiaoKai
     * @Description 修改狗
     * @Date 20:34 2021/5/14
     * @param id
	 * @param productsDog
     * @return com.yk.anima.response.ResponseResult
     */
    @Override
    @PutMapping("/update/{id}")
    public ResponseResult update(@PathVariable("id") int id, @RequestBody ProductsDog productsDog) {
        return productsDogServlet.update(id,productsDog);
    }

    /**
     * @Author xiaoKai
     * @Description 分页操作
     * @Date 22:14 2021/5/14
     * @param page
	 * @param size
	 * @param name
     * @return com.yk.anima.response.QueryResponseResult
     */
    @Override
    @GetMapping("/findByPage/{page}/{size}")
    public QueryResponseResult findByPage(@PathVariable("page") int page,
                                          @PathVariable("size") int size, String name) {

        return productsDogServlet.findByPage(page,size,name);
    }
}
